package com.tjian.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DoubleConverter;
import com.thoughtworks.xstream.converters.basic.FloatConverter;
import com.thoughtworks.xstream.converters.basic.IntConverter;
import com.thoughtworks.xstream.converters.basic.LongConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;

import net.oschina.app.AppException;
import net.oschina.app.util.TLog;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * xml解析工具类
 *
 * @author
 */

public class StringUtil
{
    public static String convertStreamToString(InputStream is)
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line = null;
        try
        {
            while ((line = reader.readLine()) != null)
            {
                sb.append(line);
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                is.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }

    public static String bufferedReaderToString(BufferedReader bufferedReader)
    {
        String temp = "";
        String s = "";
        try
        {
            while ((temp = bufferedReader.readLine()) != null)
            {
                System.out.println("==========,_20161116_091626,\n" + TypeUtil.typeToString("temp", temp));
                s = s + temp;
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        System.out.println("==========,_20161116_091623,\n" + TypeUtil.typeToString("s", s));
        return s;
    }

    /**
     * 判断字符串是否是整数
     */
    public static boolean isInteger(String value)
    {
        try
        {
            Integer.parseInt(value);
            return true;
        }
        catch (NumberFormatException e)
        {
            return false;
        }
    }
}
